﻿
@{
    Layout = "~/Views/Shared/_Edit.cshtml";
}
<form class="layui-form" action="" style="margin-top:20px;">
    <div class="layui-form-item">
        <label class="layui-form-label">旧密码</label>
        <div class="layui-input-inline">
            <input type="password" name="OldPassword" lay-verify="pass" placeholder="旧密码" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux">请填写6到20位密码</div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">新密码</label>
        <div class="layui-input-inline">
            <input type="password" name="Password" lay-verify="pass" placeholder="新密码" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux">请填写6到20位密码</div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="submit">保存</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
@section script{
    <script>
        layui.use("form", function () {
            var form = layui.form
                , layer = layui.layer
                , $ = layui.$;
            
            //监听提交
            form.on('submit(submit)', function (data) {
                var formData = data.field;
                $.post("SavePassword", formData, function (d) {
                    if (d.code === 0) {
                        layer.msg(d.msg, { icon: 1 });
                    }
                    else {
                        layer.msg(d.msg, { icon: 2 });
                    }
                })
                return false;
            });
            //自定义验证规则
            form.verify({
                pass: [/^\w{6,20}$/, '密码必须6到20位']
            });
        });
    </script>
}

